//
//  OAWebDriver.h
//  OARetail
//
//  Created by ChenJie on 5/15/20.
//  Copyright © 2020 Mist. All rights reserved.
//

#import <Foundation/Foundation.h>
#import "OAError.h"
#import "OAWebDriverConfig.h"

extern NSString * const OAWebContentTypeKey;
extern NSString * const OAWebContentTypeApplicationJson;
extern NSString * const OAWebContentTypeFormUrlencoded;

typedef void (^OAWebDriverSuccessHandler)(id responseObject);
typedef void (^OAWebDriverFailureHandler)(OAError *error);
typedef void (^OAWebDriverProgressHandler)(NSProgress *progress);

@interface OAWebDriver : NSObject

@property (nonatomic, strong, class, readonly) OAWebDriverConfig *config;

+ (instancetype)driver;

/* Get */
- (NSURLSessionDataTask *)get:(NSString *)urlString
                   parameters:(NSDictionary *)parameters
                      headers:(NSDictionary *)headers
                      success:(OAWebDriverSuccessHandler)success
                      failure:(OAWebDriverFailureHandler)failure;

/* Post */
- (NSURLSessionDataTask *)post:(NSString *)urlString
                    parameters:(NSDictionary *)parameters
                       headers:(NSDictionary *)headers
                       success:(OAWebDriverSuccessHandler)success
                       failure:(OAWebDriverFailureHandler)failure;

/* Post raw data */
- (NSURLSessionDataTask *)post:(NSString *)urlString
                       rawData:(NSData *)rawData
                       headers:(NSDictionary *)headers
                       success:(OAWebDriverSuccessHandler)success
                       failure:(OAWebDriverFailureHandler)failure;

/* Download */
- (NSURLSessionDataTask *)download:(NSString *)urlString
                       destination:(NSString *)destination
                          progress:(OAWebDriverProgressHandler)progress
                           success:(OAWebDriverSuccessHandler)success
                           failure:(OAWebDriverFailureHandler)failure;

/* Upload */
- (NSURLSessionDataTask *)upload:(NSString *)urlString
                      parameters:(NSDictionary *)parameters
                         headers:(NSDictionary *)headers
                        dataInfo:(NSDictionary *)dataInfo
                         success:(OAWebDriverSuccessHandler)success
                         failure:(OAWebDriverFailureHandler)failure;

@end
